<html class="x-admin-sm">
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.1</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <script type="text/javascript" src="./js/cookie.js"></script>
    <link rel="stylesheet" type="text/css" href="layui/css/layui.css"/>
	<script src="layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">演示</a>
        <a>
          <cite>导航元素</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
      <div class="layui-form-item" style="margin-left: 10px;margin-top: 10px;">
			<form class="layui-form" action="" method="post" onsubmit="return false;">
				<label class="layui-form-mid">教师卡号：</label>
				<div class="layui-input-inline" style="width: 100px;">
					<input class="layui-input" id="name1" />
				</div>
				
				<label class="layui-form-mid">科室：</label>
				<div class="layui-input-inline" style="width: 100px;">
					<select id="type1">
						<option value="">-请选择-</option>
					</select>
				</div>
				<div class="layui-input-inline" style="width: 100px;">
					<button id="search" class="layui-btn">搜索</button>
				</div>
			</form>
			<form class="layui-form layui-col-md6 x-so"
				enctype="multipart/form-data" method="post" action="/X-admin/ExTeachers">
				文件 <input class="layui-input" type="file" name="file" /> <input class="layui-btn" type="submit"
					value="上传" />
			</form>
                
		</div>
		
		<div id="updateDiv" style="display: none;margin-left: 10px;">
			<form id="updateForm" class="layui-form" lay-filter="updateForm" action="" method="post" onsubmit="return false;">
				<div class="layui-form-item"style="display:none" >
					<label class="layui-form-mid"></label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" name="id"  />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">卡号：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" name="cardno" lay-verify="required|vname"/>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">教师名字：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" name="name" lay-verify="required|vname"/>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">性别：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" name="sex" lay-verify="required|vname"/>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">科室：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<select id="sectionid" name="id" lay-verify="required">
							<option value="">-请选择-</option>
						</select>
					</div>
				</div>
				<div class="layui-form-item" style="text-align: center;">
					<button class="layui-btn" id="updateBtn">修改</button>
				</div>
			</form>
		</div>
		
		<div id="addDiv" style="display: none;margin-left: 10px;">
			<form id="addForm" class="layui-form" action="" method="post" onsubmit="return false;">
			<div class="layui-form-item">
					<label class="layui-form-mid">卡号：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" name="cardno" lay-verify="required|vname"/>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">教师名字：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" name="name" lay-verify="required|vname"/>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">性别：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" name="sex" lay-verify="required|vname"/>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">科室：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<select id="sectionid" name="id" lay-verify="required">
							<option value="">-请选择-</option>
						</select>
					</div>
				</div>
				<div class="layui-form-item" style="text-align: center;">
					<button id="addBtn" class="layui-btn" lay-filter="test" lay-submit>添加</button>
				</div>
			</form>
		</div>
		
     <script type="text/html" id="top">
		<button class="layui-btn" lay-event="add">添加</button> 
        <button class="layui-btn" lay-event=""><a onclick="downloadfile();">数据导出</a></button>
	</script>
      <table class="layui-table" id="tab" lay-filter="tfil"></table>
     

    </div>
    <script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>

</script>

<script>		
function downloadfile(){
    window.location.href="/X-admin/OutTeachers";

}
			layui.use(['table','form','laydate','tree'],function(){
				var table=layui.table,
					form=layui.form,
					$=layui.$,
					tree=layui.tree,
					laydate=layui.laydate;
					
				laydate.render({ 
					  elem: '#addTime'
					  ,type: 'year'
					  ,width:500
					});

				table.render({
					elem:'#tab',
					url:'findTeachers',
					method:'Get',
					page:true,
					toolbar:'#top',
					cols:[[
						{field:'id',title:'ID'},
						{field:'cardno',title:'卡号'},
						{field:'id',title:'科室',templet:'<div>{{d.sections.name}}</div>'},
						{field:'name',title:'姓名'},
						{field:'sex',title:'性别'},
						//{field:'SectionID',title:'科室'},
						{field:'status',title:'状态',templet:function(d){if(d.status=='0'){
							return '正常';
						}else{
							return '异常';
						}}},
						{title:'操作工具栏',toolbar: '#barDemo',width:300}
						
					]],id:'ttt'
				});
			   
				 $(function(){
					$.post('findSection',{},function(data){
						var h='';
						for (var i = 0; i < data.length; i++) {
							h+='<option value="'+data[i].id+'">'+data[i].name+'</option>';
						}
					
						$("select").append(h);
						form.render('select');
					})
				})
				
				active={
					reload:function(){
						table.reload('ttt',{
							where:{
								'cardno':$("#name1").val(),
								'id':$("#type1").val(),
								
							}
						})
					}
				}
				
				$("#search").click(function(){
					active.reload();
				});
				
				table.on("toolbar(tfil)",function(obj){
					if(obj.event=="add"){
						layer.open({
							type:1,
							title:'添加',
							content:$("#addDiv"),
							area:['550px','600px']
						})
					}
				});
				
				

				 form.on('submit(test)',function(){
					var data=$("#addForm").serialize();
					
					$.post('addTeachers',data,function(res){
						if(res>0){
							active.reload();
							layer.closeAll();
							layer.msg("添加成功！");
						}
					},"json")
					
				}) 
				
				//监听行工具事件
				  table.on('tool(tfil)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
				    var data = obj.data //获得当前行数据
				    ,layEvent = obj.event; //获得 lay-event 对应的值
				    if(layEvent === 'detail'){
				      layer.msg('查看操作');
				    } else if(layEvent === 'del'){
				    	var id=data.id;
				    	/* $.post('delVideo',{'vid':data.vid},function(res){
							if(res>0){
								active.reload();
								
								layer.msg("删除成功！");
							}
						},"json") */
						$.ajax({          
					       	 url:"delTeachers", 
					         dataType:"json",  
					         type:"delete", 
					         data:{"id":id},
					         success:function(data){
					        	 active.reload();
					         },      
					         error:function(){
					        	 
					         }
					});
				    } else if(layEvent === 'edit'){
				    	form.val("updateForm",data);
				    	layer.open({
							type:1,
							title:'修改',
							content:$("#updateDiv"),
							area:['550px','600px']
						})
				    }
				  });
				$("#updateBtn").click(function(){
					
					$.post("upTeachers",$("#updateForm").serialize(),function(res){
						if(res="1"){
							layer.msg("sucess");
							layer.closeAll();
							active.reload();
						}
					},"text")
				
				}) 
				
                  
			
			})
		</script>
  
  </body>

</html>